package me.zk.practice1.s;

/**
 * @author zhangkai
 * @date 2023/7/13 10:05
 */
public class LS_Offer_58 {
    public String reverseLeftWords(String s, int n) {
        StringBuffer sb = new StringBuffer();
        char[] chars = s.toCharArray();
        for (int i = n; i < chars.length; i++) {
            sb.append(chars[i]);
        }
        for (int i = 0; i < n; i++) {
            sb.append(chars[i]);
        }

        return sb.toString();
    }

    public static String reverseWords(String s) {
        String[] ss = s.trim().split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = ss.length-1; i >=0; i--) {
            if (ss[i].equals("")) {
                continue;
            }
            sb.append(ss[i]);
            if (i!=0) {
                sb.append(" ");
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        reverseWords("a good   example");
    }
}
